package com.way.demo.config;

import com.way.demo.filter.MyFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.servlet.Filter;

/**
 * @author lipingwei
 * @create 2021-01-21 16:32
 */
@Configuration
//@Import(SpringUtil.class)
public class MyFilterConfig {

    @Bean
    public FilterRegistrationBean myFilterBean(MyFilter filter) {
        FilterRegistrationBean<Filter> filterRegistrationBean = new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(filter);//设置为自定义的过滤器MyFilter
        filterRegistrationBean.addUrlPatterns("/*");//拦截所有请求
        //放行的url 如何配置？
        //filterRegistrationBean.set
        filterRegistrationBean.setOrder(1);//优先级为1
        return filterRegistrationBean;
    }

}
